import {message} from 'antd';
import {formatMessage} from './intl';

export const deliverValidator = data => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data || (!data.noRateReason && data.fullRateAbnormal))
        emptyErrors.push(formatMessage({
            id: 'validator.empty.noRateReason',
            defaultMessage: '未达到满足率原因'
        }));
        
    if(!data || (!data.noTimeSubjectiveReason && data.deliveryAbnormal))
        emptyErrors.push(formatMessage({
            id: 'validator.empty.noTimeSubjectiveReason)',
            defaultMessage: '未达到及时率主观原因'
        }));

    if(!data || (!data.noTimeObjectiveReason && data.deliveryAbnormal))
        emptyErrors.push(formatMessage({
            id: 'validator.empty.noTimeObjectiveReason)',
            defaultMessage: '未达到及时率客观原因'
        }));
           
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填！'
        })}`);
        return false;
    }
    return true;
};
